package com.ja.openchat.views;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.blankj.utilcode.util.SizeUtils;
import com.ja.openchat.R;
import com.lxj.xpopup.core.CenterPopupView;
import com.lxj.xpopup.util.XPopupUtils;
import com.zy.openchat.util.Common;

import org.jetbrains.annotations.NotNull;

public class VerifyPayPasswordDialog extends CenterPopupView {
    private VerificationCodeView.OnInputFinishListener mCallback;
    private String mPrice;
    private String mPayType;

    public VerifyPayPasswordDialog(@NotNull Context context, String price, VerificationCodeView.OnInputFinishListener callback) {
        super(context);
        mCallback = callback;
        mPrice = price;
    }


    public VerifyPayPasswordDialog(@NotNull Context context, String price, String payType, VerificationCodeView.OnInputFinishListener callback) {
        super(context);
        mCallback = callback;
        mPrice = price;
        mPayType = payType;
    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.dialog_verify_pay_password;
    }

    @Override
    protected void onCreate() {
        findViewById(R.id.close_btn).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        TextView pay_type = findViewById(R.id.pay_type);
        if (!TextUtils.isEmpty(mPayType)) {
            pay_type.setText(mPayType);
        }
        TextView red_money = findViewById(R.id.red_money);
        red_money.setText(mPrice);
        VerificationCodeView ver_code_view = findViewById(R.id.ver_code_view);
        ViewGroup.LayoutParams layoutParams = (ViewGroup.LayoutParams) ver_code_view.getLayoutParams();
        layoutParams.width = getPopupWidth() - SizeUtils.dp2px(30);
        layoutParams.height = SizeUtils.dp2px(45);
        ver_code_view.setLayoutParams(layoutParams);
        ver_code_view.requestLayout();
        ver_code_view.setOnInputFinishListener(new VerificationCodeView.OnInputFinishListener() {
            @Override
            public void onInputFinish(String text) {
                if (mCallback != null) {
                    mCallback.onInputFinish(Common.MD5(text));
                }
                dismiss();
            }
        });
    }

    @Override
    protected int getPopupWidth() {
        return (int) (XPopupUtils.getAppWidth(getContext()) * .8f);
    }
}
